package controller

import (
	"github.com/gin-gonic/gin"
	"web/app"
	"web/app/server"
)

type c_power struct {
	srv *server.Power
}

func (c2 *c_power) Charge(c *gin.Context) {
	err := c2.srv.Charge(c)
	if err != nil {
		app.Response(c, 400, err.Error())
	} else {
		app.Response(c, 200, "充值成功")
	}
}

func (c2 *c_power) GetAll(c *gin.Context) {
	err, list := c2.srv.GetAll(c)
	if err != nil {
		app.Response(c, 400, err.Error())
	} else {
		app.Response_list(c, 200, "查询成功", list)
	}
}

func (c2 *c_power) Edit(c *gin.Context) {
	err := c2.srv.Edit(c)
	if err != nil {
		app.Response(c, 400, err.Error())
	} else {
		app.Response(c, 200, "修改成功")
	}
}

func (c2 *c_power) Check(c *gin.Context) {
	err, apply, power := c2.srv.Check(c)
	if err != nil {
		app.Response(c, 400, err.Error())
	} else {
		app.Response_Encrypt(c, 200, "效验成功", gin.H{"a": apply, "p": power})
	}

}
func (c2 *c_power) Login_User(c *gin.Context) {
	err, token := c2.srv.Login_User(c)
	if err != nil {
		app.Response(c, 400, err.Error())
	} else {
		app.Response_Encrypt(c, 200, "登陆成功", gin.H{"token": token})
	}
}

func (c2 *c_power) Login_Cdk(c *gin.Context) {

}
func (c2 *c_power) Sub(c *gin.Context) {
	err := c2.srv.Sub(c)
	if err != nil {
		app.Response(c, 400, err.Error())
	} else {
		app.Response(c, 200, "扣除成功")
	}
}
